Open
Conversation
9c0208f to
eae465e
Compare
b186ecc to
f529484
Compare
…_examples.sh and tpm2_tools_test.sh to make test for fwtpm as well
danielinux
requested changes
Apr 3, 2026
src/fwtpm/fwtpm_nv.c
Outdated
Comment on lines
+339
to
+342
| pkt.pos = 2; /* skip size we already read */ | ||
| TPM2_Packet_ParsePublic(&pkt, &pub2b); | ||
| XMEMCPY(pub, &pub2b.publicArea, sizeof(TPMT_PUBLIC)); | ||
| *pos += pubSz; |
Member
There was a problem hiding this comment.
This calls TPM2_Packet_ParsePublic which parses the size again. I think restoring might corrupt saved records. Please verify with a test
| /* Check if journal has space */ | ||
| if (ctx->nvWritePos + entrySize > hal->maxSize) { | ||
| /* Compact and retry */ | ||
| rc = FWTPM_NV_Save(ctx); |
Member
There was a problem hiding this comment.
cyclic recursion seems possible between FWTPM_NV_Save and FwNvAppendEntry if compacting is not sufficient the functions will keep calling each other
src/fwtpm/fwtpm_command.c
Outdated
| FwFlushAllSessions(ctx); | ||
| } | ||
|
|
||
| FWTPM_NV_Save(ctx); |
Member
There was a problem hiding this comment.
Return value is discarded here, this functions will return success regardless of FWTPM_NV_Save result. Review error handling in this function.
- Fixed LE/BE endianness mismatch in FwNvMarshalPublic/FwNvUnmarshalPublic - Added nvCompacting guard to prevent infinite recursion between FwNvAppendEntry and FWTPM_NV_Save - Check FWTPM_NV_Save return value in FwCmd_Shutdown and other callers - Reinitialize hash context per iteration in TPM2_KDFe_ex for multi-block derivation - Align packet->pos to inSensSize boundary in ParseSensitiveCreate - Clean up wolfCrypt resources if FWTPM_NV_Init fails in FWTPM_Init - Reset g_initialized on fuzzer reinit failure - Fix configure.ac so --enable-swtpm=uart doesn't force TIS mode - Update README command count from 103/91% to 105/93%
- Fixed memory leak in FwComputeRpHash — initialized rc = 0, added FWTPM_FREE_VAR(hashCtx) before both early returns to prevent heap leak under WOLFTPM_SMALL_STACK - Removed static from eccUniqueBuf in FwCmd_CreatePrimary — eliminates thread-safety risk and stale data persistence across calls (132-byte buffer is fine on stack) - Initialized rc = TPM_RC_SUCCESS in FWTPM_ProcessCommand — prevents use of uninitialized variable - Added XMEMSET(cmdAuths, 0, sizeof(cmdAuths)) in FWTPM_ProcessCommand — zeroes auth struct array to prevent use of garbage data on partial parse - Added auth-parse error check — if auth area parsing fails (e.g. TPM_RC_AUTHSIZE), returns error response instead of falling through to command dispatch - Moved pwSz/avSz into inner scope — declared where actually used instead of function scope - Added TPM2_ForceZero(&bindAuth, ...) in FwCmd_StartAuthSession — zeroizes hierarchy auth secrets before scope exit - Fixed NV handle mask consistency — changed == NV_INDEX_FIRST to == (NV_INDEX_FIRST & 0xFF000000) to match style elsewhere - Added wc_HmacInit() in FwWrapPrivate — call wc_HmacInit before wc_HmacSetKey, matching pattern used in FwComputeSessionHmac and FwDeriveWrapKey - Added wc_HmacInit() in FwUnwrapPrivate — same fix for the unwrap path - Fixed UART (void)port suppression — removed erroneous cast that hid the fact port is used later - Added NULL check before atoi(port) — prevents undefined behavior if port is NULL - Restored idx >= inputSz bounds check in TPM2_ASN_DecodeX509Cert — defense-in-depth against OOB read on malformed certificates - Restored *sigSz < 3 minimum in TPM2_ASN_RsaUnpadPkcsv15 — valid PKCS#1 v1.5 needs at least 0x00|0x01|0xFF - Fixed summary alignment — consistent column spacing for fwTPM output lines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TPM2_Packet_ParseU16Bufvariant for safer response parsingfwTPM Server
Core TPM 2.0 command processing in
src/fwtpm/:fwtpm_command.c— 105 command handlers with full auth, sessions, parameter encryptionfwtpm_nv.c— TLV journal NV storage (file-based default, HAL-abstracted for flash)fwtpm_io.c— Socket transport (mssim + swtpm protocol auto-detection)fwtpm_tis.c/fwtpm_tis_shm.c— TIS register interface via POSIX shared memoryfwtpm_crypto.c— Key generation, sign/verify, seed encrypt/decrypt helpersBuild:
./configure --enable-fwtpm && makeExample: wolfSSL/wolftpm-examples#1
Primary Key Derivation (TPM 2.0 Part 1 Section 26)
UART Transport (
--enable-swtpm=uart)New transport option for wolfTPM client library to communicate with embedded fwTPM over serial:
./configure --enable-swtpm=uart— uses termios serial I/O instead of TCP socketsTPM2_SWTPM_HOSTenv var selects serial device at runtimeTesting
scripts/tpm2_tools_test.sh)examples/run_examples.sh)tests/fuzz/)scripts/fwtpm_emu_test.sh)